package com.gaoxin.api.contronller.feecontroller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.eduentity.Clazz;
import com.gaoxin.api.entity.feeentity.FinancialTarget;
import com.gaoxin.api.service.feeservice.FinancialTargetService;
import com.gaoxin.api.service.feeservice.QueryStuFeeService;
import com.gaoxin.api.service.stuservice.QueryStuNumberService;
import com.google.common.collect.Maps;

/**
 * 统计缴费数据
 * @author mx
 *
 */
@RestController
@RequestMapping("/app/financialTarget")
public class FinancialTargetController {
	
	@Autowired
	private FinancialTargetService financialTargetService;
	@Autowired
	private QueryStuFeeService queryStuFeeService;
	@Autowired
	private QueryStuNumberService queryStuNumberService;
	
	/**
	 * 统计缴费数据
	 * @param financialTarget
	 * @return
	 */
	@RequestMapping(value = "/queryFinanceNumber", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryFinanceNumber(@RequestBody FinancialTarget financialTarget){
		String returnStr = "";
		Map<String, Object> maps = Maps.newHashMap();
		try {
			FinancialTarget queryFinanceNumber = financialTargetService.queryFinanceNumber(financialTarget);
			if(queryFinanceNumber !=null){
				maps.put("results", queryFinanceNumber);
				returnStr = JSON.toJSONString(maps);
			}else{
				maps.put("errmsg", "未查询到对应信息");
				returnStr = JSON.toJSONString(maps);
			}
		} catch (Exception e) {
			e.printStackTrace();
			maps.put("errmsg", "查询到对应信息错误");
			returnStr = JSON.toJSONString(maps);
		}
		return returnStr;
	}
	
	/**
	 * 查询所有的二级院系
	 * @param paramMap
	 * @return
	 */
	@RequestMapping(value = "/queryDept", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryDept() {
		String jsonData = null;
		try {
			List<Clazz> list = queryStuFeeService.queryDept();
			Map<String, Object> map = Maps.newHashMap();
			if(list.size()!=0&&list!=null){
				map.put("code", "0");
				map.put("results",list);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100202");
				map.put("errmsg", "无院系信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 根据院系查询所属专业信息
	 * @return
	 */
	@RequestMapping(value = "/queryMajor", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryMajor(@RequestBody Clazz clazz) {
		String jsonData = null;
		try {
			List<Clazz> major = queryStuFeeService.queryMajor(clazz);
			Map<String, Object> map = Maps.newHashMap();
			if(major!=null){
				map.put("code", "0");
				map.put("results",major);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100203");
				map.put("errmsg", "无该院系对应的专业信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 根据专业查询班级
	 * @param clazz
	 * @return
	 */
	@RequestMapping(value = "/queryClazz", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryClazz(@RequestBody Clazz clazz) {
		String jsonData = null;
		try {
			List<Clazz> queryClazz = queryStuFeeService.queryClazz(clazz);
			Map<String, Object> map = Maps.newHashMap();
			if(queryClazz!=null){
				map.put("code", "0");
				map.put("results",queryClazz);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100204");
				map.put("errmsg", "无该专业对应的班级信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 查询年级
	 * @return
	 */
	@RequestMapping(value = "/queryGrade", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryGrade() {
		String jsonData = null;
		try {
			String[] grade = queryStuNumberService.getGrade();
			Map<String, Object> map = Maps.newHashMap();
			if(grade!=null){
				map.put("code", "0");
				map.put("results",grade);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100205");
				map.put("errmsg", "无年级信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 查询学年
	 * @return
	 */
	@RequestMapping(value = "/queryYear", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryYear() {
		String jsonData = null;
		try {
			String[] year = financialTargetService.getYear();
			Map<String, Object> map = Maps.newHashMap();
			if(year!=null){
				map.put("code", "0");
				map.put("results",year);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100205");
				map.put("errmsg", "无学年信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	
}
